#include <cstdio>
#include <iostream>

using namespace std; 

#define N 100001

struct student_t {
	student_t *left, *right; 
	int id; 
}; 

student_t g_student[N]; 
student_t g_head; 

inline int read(void) {
    char ch;
    int num=0; 
	int sign=1;
	
	// skip blank character and get neigetive sign if it exist. 
    for (ch=getchar(); ch<'0'||ch>'9'; ch=getchar()) {
		if(ch=='-') {
			sign = -1;
		}
	}
	
    while(ch>='0' && ch<='9') {
		num = num*10 + (ch-'0'); 
		ch = getchar();
	}
    return sign*num; 
}


void insert(student_t *left, student_t *right, student_t *node)
{
	node->left = left; 
	node->right = right; 
	left->right = node; 
	right->left = node; 
}

void remove(student_t *node)
{
	student_t *left = node->left; 
	student_t *right = node->right; 
	
	if (left==node || right==node)
		return; 

	left->right = right; 
	right->left = left; 
	node->left = node->right = node; 
}

int main()
{
	int i, n, m, k, p; 
	student_t *sp, *left, *right; 
	
	//freopen("p1160.in", "r", stdin); 
	
	g_head.left = g_head.right = &g_head; 
	
	for (i=0; i<N; i++) {
		sp = g_student+i; 
		sp->left = sp->right = sp; 
		sp->id = i; 
	}
	insert(&g_head, &g_head, &g_student[1]); 
	
	scanf("%d", &n); 
	for(i=2; i<=n; i++) {
		k = read(); 
		p = read(); 
		if (p==0) {
			right = &g_student[k]; 
			left = right->left; 
		} else {
			left =  &g_student[k]; 
			right = left->right; 
		}
		insert(left, right, &g_student[i]); 
	}
	scanf("%d", &m); 
	for(i=1; i<=m; i++) {
		k = read(); 
		remove(&g_student[k]); 
	}
	
	for (sp=g_head.right; sp!=&g_head; sp=sp->right) {
		printf("%d ", sp->id); 
	}
	printf("\n"); 
	
	return 0; 
}


